/**
 * 
 */
package org.swing.utility.input.util;

import java.util.prefs.BackingStoreException;

import org.swing.utility.input.imp.JavaBackedPreferencesImpl;
import org.swing.utility.input.imp.Preferences;

/**
 * @author lqnhu
 *
 */
public class JavaBackedPreferencesManagerImpl extends PreferencesManager {
	private static final String APPLICATION_PREFERENCES = "application_preferences";

	@SuppressWarnings("rawtypes")
	public Preferences getApplicationPreferences(Class c) {
		return new JavaBackedPreferencesImpl(APPLICATION_PREFERENCES,
				c.getName());
	}

	public Preferences getApplicationPreferences(String preferencesId) {
		return new JavaBackedPreferencesImpl(APPLICATION_PREFERENCES,
				preferencesId);
	}

	@SuppressWarnings({ "rawtypes" })
	public Preferences getPreferencesForSet(String setId, Class c) {
		return new JavaBackedPreferencesImpl(setId, c.getName());
	}

	public Preferences getPreferencesForSet(String setId, String preferencesId) {
		return new JavaBackedPreferencesImpl(setId, preferencesId);
	}

	/**
	 * Resets the preferences to the factory settings. In most cases this will
	 * simply wipe out all preferences.
	 */
	@Override
	public void resetPreferencesToFactorySettings() {
		try {
			java.util.prefs.Preferences userRoot = java.util.prefs.Preferences
					.userRoot();
			java.util.prefs.Preferences protegePreferencesRoot = userRoot
					.node(JavaBackedPreferencesImpl.PROTEGE_PREFS_KEY);
			protegePreferencesRoot.removeNode();
		} catch (BackingStoreException e) {
			e.printStackTrace();
		}
	}
}